package com.lmaye.design.patterns.creation.singleton;

import java.util.Objects;

/**
 * -- 双重检查(推荐使用)
 *
 * <pre>
 *     优点：
 *     - 实现了懒加载效果,同时也保证了线程同步问题，效率也较高
 *     缺点：
 *     -
 * </pre>
 *
 * @author lmay.Zhou
 * @date 2020/11/13 15:37 星期五
 * @qq 379839355
 * @email lmay@lmaye.com
 * @since JDK1.8
 */
public class SingletonDoubleCheck {
    private static SingletonDoubleCheck instance;

    private SingletonDoubleCheck() {
    }

    public static SingletonDoubleCheck getInstance() {
        if(Objects.isNull(instance)) {
            synchronized (SingletonDoubleCheck.class) {
                if(Objects.isNull(instance)) {
                    instance = new SingletonDoubleCheck();
                }
            }
        }
        return instance;
    }
}
